package com.resys.service.impl;

import java.time.LocalDateTime;
import java.util.Date;
import java.util.List;

import javax.annotation.Resource;

import com.resys.entity.dto.LogDto;
import org.springframework.stereotype.Service;

import com.resys.entity.enums.PageSize;
import com.resys.entity.query.RoomstatuslogQuery;
import com.resys.entity.po.Roomstatuslog;
import com.resys.entity.vo.PaginationResultVO;
import com.resys.entity.query.SimplePage;
import com.resys.mappers.RoomstatuslogMapper;
import com.resys.service.RoomstatuslogService;
import com.resys.utils.StringTools;


/**
 *  业务接口实现
 */

@Service("roomstatuslogService")
public class RoomstatuslogServiceImpl implements RoomstatuslogService {

	@Resource
	private RoomstatuslogMapper<Roomstatuslog, RoomstatuslogQuery> roomstatuslogMapper;

	/**
	 * 根据条件查询列表
	 */
	@Override
	public List<Roomstatuslog> findListByParam(RoomstatuslogQuery param) {
		return this.roomstatuslogMapper.selectList(param);
	}

	/**
	 * 根据条件查询列表
	 */
	@Override
	public Integer findCountByParam(RoomstatuslogQuery param) {
		return this.roomstatuslogMapper.selectCount(param);
	}

	/**
	 * 分页查询方法
	 */
	@Override
	public PaginationResultVO<Roomstatuslog> findListByPage(RoomstatuslogQuery param) {
		int count = this.findCountByParam(param);
		int pageSize = param.getPageSize() == null ? PageSize.SIZE15.getSize() : param.getPageSize();

		SimplePage page = new SimplePage(param.getPageNo(), count, pageSize);
		param.setSimplePage(page);
		List<Roomstatuslog> list = this.findListByParam(param);
		PaginationResultVO<Roomstatuslog> result = new PaginationResultVO(count, page.getPageSize(), page.getPageNo(), page.getPageTotal(), list);
		return result;
	}

	/**
	 * 新增
	 */
	@Override
	public Integer add(Roomstatuslog bean) {
		return this.roomstatuslogMapper.insert(bean);
	}

	/**
	 * 批量新增
	 */
	@Override
	public Integer addBatch(List<Roomstatuslog> listBean) {
		if (listBean == null || listBean.isEmpty()) {
			return 0;
		}
		return this.roomstatuslogMapper.insertBatch(listBean);
	}

	/**
	 * 批量新增或者修改
	 */
	@Override
	public Integer addOrUpdateBatch(List<Roomstatuslog> listBean) {
		if (listBean == null || listBean.isEmpty()) {
			return 0;
		}
		return this.roomstatuslogMapper.insertOrUpdateBatch(listBean);
	}

	/**
	 * 多条件更新
	 */
	@Override
	public Integer updateByParam(Roomstatuslog bean, RoomstatuslogQuery param) {
		StringTools.checkParam(param);
		return this.roomstatuslogMapper.updateByParam(bean, param);
	}

	/**
	 * 多条件删除
	 */
	@Override
	public Integer deleteByParam(RoomstatuslogQuery param) {
		StringTools.checkParam(param);
		return this.roomstatuslogMapper.deleteByParam(param);
	}

	/**
	 * 根据LogId获取对象
	 */
	@Override
	public Roomstatuslog getRoomstatuslogByLogId(Integer logId) {
		return this.roomstatuslogMapper.selectByLogId(logId);
	}

	/**
	 * 根据LogId修改
	 */
	@Override
	public Integer updateRoomstatuslogByLogId(Roomstatuslog bean, Integer logId) {
		return this.roomstatuslogMapper.updateByLogId(bean, logId);
	}

	/**
	 * 根据LogId删除
	 */
	@Override
	public Integer deleteRoomstatuslogByLogId(Integer logId) {
		return this.roomstatuslogMapper.deleteByLogId(logId);
	}

	@Override
	public void write(LogDto logDto) {
		Roomstatuslog log = new Roomstatuslog();
		log.setChangedBy(logDto.getUserId());
		log.setRoomId(logDto.getRoomId());
		log.setChangedTime(new Date());
		log.setOldStatus(logDto.getOldStatus());
		log.setNewStatus(logDto.getNewStatus());
		this.roomstatuslogMapper.insert(log);
	}

	@Override
	public Integer getCountlog(String userId, LocalDateTime start, LocalDateTime end) {
		return this.roomstatuslogMapper.getCountLog(userId,start,end);
	}
}